var t, e, n, i;

t = require("../@babel/runtime/helpers/classCallCheck"), e = require("../@babel/runtime/helpers/createClass"), 
n = new Map(), i = function() {
    function i(e) {
        t(this, i), Object.assign(this, e), this.run = this.run.bind(this), this.on = this.on.bind(this), 
        this._int();
    }
    return e(i, [ {
        key: "_int",
        value: function() {
            var t = this, e = [], n = Object.prototype.toString.call(this.text), i = wx.getSystemInfoSync().windowWidth, r = getCurrentPages()[getCurrentPages().length - 1];
            if ("[object Array]" === n) e = this.text.map(function(e) {
                return e.length * t.size;
            }); else {
                if ("[object String]" !== n) return void console.error("type: " + n.slice(7, -1) + " is invalid");
                e[0] = this.text.length * this.size, this.text = [ this.text ];
            }
            this.pageContext = r, this.windowWidth = i, this.lengthArr = e;
        }
    }, {
        key: "_getEventType",
        value: function() {
            return [ "ready", "run", "change" ];
        }
    }, {
        key: "_firstLetterUpper",
        value: function(t) {
            return t.charAt(0).toUpperCase() + t.slice(1);
        }
    }, {
        key: "run",
        value: function() {
            var t = this;
            if (this.pageContext && this.windowWidth && this.lengthArr) {
                var e = 0, i = 0;
                "function" == typeof n.get("onRun") && n.get("onRun")(e), function r(a) {
                    setTimeout(function() {
                        -t.marqueeDistance < a ? t.marqueeDistance = t.marqueeDistance - t.marqueePace : (t.lengthArr[e + 1] ? (i = 0, 
                        e += 1) : e = 0, "function" == typeof n.get("onChange") && n.get("onChange")(e), 
                        t.marqueeDistance = t.windowWidth);
                        var s = t.marqueeDistance, o = t.text, h = t.size, u = t.orientation, l = o[e + 1], c = o[o.length - e], g = o[Math.floor(Math.random() * o.length - 1)], f = o[Math.floor(Math.random() * o.length - 2)], p = o[Math.floor(Math.random() * o.length - 1)];
                        0 == e && (c = o[o.length - 1]), 0 == i ? t.pageContext.setData({
                            marqueeDistance: s,
                            text: o[e],
                            text2: l,
                            text3: c,
                            text4: g,
                            text5: f,
                            text6: p,
                            size: h,
                            orientation: u
                        }) : t.pageContext.setData({
                            marqueeDistance: s,
                            text: o[e],
                            size: h,
                            orientation: u
                        }), i = 1, r(t.lengthArr[e]);
                    }, t.interval);
                }(this.lengthArr[e]);
            }
        }
    }, {
        key: "on",
        value: function(t, e) {
            return this._getEventType().indexOf(t) > -1 ? "function" == typeof e && ("ready" === t ? e() : n.set("on" + this._firstLetterUpper(t), e)) : console.error("event: " + t + " is invalid"), 
            this;
        }
    } ]), i;
}(), module.exports.marquee = i;